package com.hq.ims.data.vo;

import com.alibaba.fastjson.annotation.JSONField;
import com.hq.authority.utils.AppUtils;
import com.hq.ims.data.config.verification.VdAdd;
import com.hq.ims.data.config.verification.VdEdit;
import com.hq.ims.data.entity.*;
import com.hq.ims.data.entityenum.*;
import com.hq.ims.data.vo.auth.BaseRowAuthVo;
import com.hq.utils.util.ListUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.mapstruct.IterableMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;


/**
 * @author 蒋柏平
 * @since 20240927
 */
@Mapper
public interface CompanyMapstruct {

    CompanyMapstruct INSTANCE = Mappers.getMapper(CompanyMapstruct.class);

    //-------------------------------- 转换VO类 --------------------------------

    @Mappings({
    })
    CompanyVo toCompanyVo(Company source);

    default List<CompanyVo> toCompanyVoList(List<Company> source) {
        if (source == null) {
            return ListUtils.newEmptyList();
        }
        return source.stream().map(this::toCompanyVo).collect(Collectors.toList());
    }


    //-------------------------------- CompanyTreeVo --------------------------------

    @Named("toCompanyTreeVo")
    @Mappings({
    })
    CompanyTreeVo toCompanyTreeVo(Company source);

    @IterableMapping(qualifiedByName = "toCompanyTreeVo")
    List<CompanyTreeVo> toCompanyTreeVoList(List<Company> source);


    //-------------------------------- 以下为自定义类[输出对象] --------------------------------

    @ApiModel(value = "原始对象的扩展类")
    @Data
    class CompanyVo extends Company {

        @ApiModelProperty(value = "证件照片")
        @NotEmpty(message = "证件照片不能为空", groups = {VdAdd.class, VdEdit.class})
        private List<AppFileMapstruct.FileVo> companyIdFiles;

        @ApiModelProperty(value = "服务地区")
        @NotEmpty(message = "服务地区不能为空", groups = {VdAdd.class, VdEdit.class})
        private List<CompanyServiceArea> serviceArea;

        @ApiModelProperty(value = "产业标记")
        @NotEmpty(message = "产业标记不能为空", groups = {VdAdd.class, VdEdit.class})
        private List<CompanyServiceType> serviceType;

        @ApiModelProperty(value = "规则说明")
        @NotEmpty(message = "规则说明不能为空", groups = {VdAdd.class, VdEdit.class})
        private List<AppFileMapstruct.FileVo> companyRuleFiles;

        @ApiModelProperty(value = "企业资质")
        @NotEmpty(message = "企业资质不能为空", groups = {VdAdd.class, VdEdit.class})
        private List<CompanyAptitudeMapstruct.CompanyAptitudeVo> companyAptitudeFiles;

        @ApiModelProperty(value = "企业备案项目")
        private List<BusiInfo> busiInfoList;

        @ApiModelProperty(value = "企业编辑类型")
        @NotEmpty(message = "企业编辑类型不能为空", groups = {VdEdit.class})
        private EnumCompanyUpdateType companyUpdateType;

        @ApiModelProperty(value = "企业是否通过")
        private Boolean companyIsPass;

        @ApiModelProperty(value = "企业拒绝理由")
        private String companyOffReason;

        @ApiModelProperty(value = "企业基本信息拒绝理由")
        private String companyBaseOffReason;

        @ApiModelProperty(value = "企业基本信息拒绝时间")
        @JSONField(format = "yyyy-MM-dd HH:mm:ss")
        private LocalDateTime companyBaseOffTime;

        @ApiModelProperty(value = "企业规则信息拒绝理由")
        private String companyRuleOffReason;

        @ApiModelProperty(value = "企业规则信息拒绝时间")
        @JSONField(format = "yyyy-MM-dd HH:mm:ss")
        private LocalDateTime companyRuleOffTime;

    }

    @ApiModel(value = "树形对象")
    @Data
    class CompanyTreeVo {

        @ApiModelProperty(value = "公司ID")
        private String companyId;

        @ApiModelProperty(value = "公司名称")
        private String companyName;

        @ApiModelProperty(value = "父ID")
        private String parentId;

        @ApiModelProperty(value = "公司级别")
        private EnumCompanyLevel companyLevel;

        @ApiModelProperty(value = "子公司")
        private List<CompanyTreeVo> childrenCompanyList;

        @ApiModelProperty(value = "公司下的部门")
        private List<CompanyDepartmentMapstruct.SimpleCompanyDepartmentVo> childrenDepartmentList;

        @ApiModelProperty(value = "员工数量")
        private Long employeeCount;

    }


    @ApiModel(value = "行级权限对象")
    @Data
    class CompanyRowAuthVo extends BaseRowAuthVo {

        //自定义其它行级权限


        //构造函数
        public CompanyRowAuthVo(Company entity) {
            //当前操作用户ID
            String userId = AppUtils.getUserId();
        }

    }


    //-------------------------------- 以下为自定义类[输入对象] --------------------------------

    @ApiModel(value = "搜索VO")
    @Data
    class PageSearchVo {

        @ApiModelProperty(value = "公司名称")
        private String companyName;

        @ApiModelProperty(value = "产业标记")
        private String serviceTypeName;

        @ApiModelProperty(value = "服务地区")
        private String serviceAreaName;

        @ApiModelProperty(value = "上级组织id")
        private String parentId;

        @ApiModelProperty(value = "上级组织名称")
        private String parentName;

        @ApiModelProperty(value = "项目名称")
        private String projectName;

        @ApiModelProperty(value = "收益规则")
        private String ruleRate;

        @ApiModelProperty(value = "证件号码")
        private String companyCardNumber;

        @ApiModelProperty(value = "证件类型")
        private String companyCardTypeName;

        @ApiModelProperty(value = "开始时间")
        private LocalDateTime startDate;

        @ApiModelProperty(value = "结束时间")
        private LocalDateTime endDate;

        @ApiModelProperty(value = "审核类型")
        private EnumCheckType checkType;

        @ApiModelProperty(value = "城市code")
        private String cityCode;

        @ApiModelProperty(value = "省份code")
        private String provinceCode;

        @ApiModelProperty(value = "产业标记id")
        private String serviceTypeId;

        @ApiModelProperty(value = "公司id")
        private String companyId;

        @ApiModelProperty(value = "审核状态")
        private EnumAuditStatus auditStatus;

    }

    @ApiModel(value = "添加和修改对象")
    @Data
    class SaveVo {

        @NotBlank(message = "数据ID不能为空", groups = {VdEdit.class})
        @ApiModelProperty(value = "数据ID")
        private String companyId;

        @ApiModelProperty(value = "创建时间 - 不需程序员处理")
        private LocalDateTime createDateTime;

        @ApiModelProperty(value = "更新时间 - 不需程序员处理")
        private LocalDateTime updateDateTime;

        @NotBlank(message = "创建用户名称不能为空", groups = {VdAdd.class, VdEdit.class})
        @Size(min = 1, max = 100, message = "创建用户名称长度不能超过100", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "创建用户名称")
        private String createUserName;

        @NotBlank(message = "更新用户名不能为空", groups = {VdAdd.class, VdEdit.class})
        @Size(min = 1, max = 100, message = "更新用户名长度不能超过100", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "更新用户名")
        private String updateUserName;

        @NotNull(message = "乐观锁 - 不需程序员处理不能为空", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "乐观锁 - 不需程序员处理")
        private Integer version;

        @NotBlank(message = "公司编号不能为空", groups = {VdAdd.class, VdEdit.class})
        @Size(min = 1, max = 255, message = "公司编号长度不能超过255", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "公司编号")
        private String companyCode;

        @NotBlank(message = "公司名称不能为空", groups = {VdAdd.class, VdEdit.class})
        @Size(min = 1, max = 255, message = "公司名称长度不能超过255", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "公司名称")
        private String companyName;

        @NotBlank(message = "企业联系人不能为空", groups = {VdAdd.class, VdEdit.class})
        @Size(min = 1, max = 100, message = "企业联系人长度不能超过100", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "企业联系人")
        private String contactPerson;

        @NotBlank(message = "联系人电话不能为空", groups = {VdAdd.class, VdEdit.class})
        @Size(min = 1, max = 100, message = "联系人电话长度不能超过100", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "联系人电话")
        private String contactMobile;

        @NotBlank(message = "省不能为空", groups = {VdAdd.class, VdEdit.class})
        @Size(min = 1, max = 100, message = "省长度不能超过100", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "省")
        private String province;

        @NotBlank(message = "市不能为空", groups = {VdAdd.class, VdEdit.class})
        @Size(min = 0, max = 100, message = "市长度不能超过100", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "市")
        private String city;

        @NotBlank(message = "区/县不能为空", groups = {VdAdd.class, VdEdit.class})
        @Size(min = 1, max = 100, message = "区/县长度不能超过100", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "区/县")
        private String district;

        @NotBlank(message = "街道不能为空", groups = {VdAdd.class, VdEdit.class})
        @Size(min = 1, max = 255, message = "街道长度不能超过255", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "街道")
        private String street;

        @NotNull(message = "企业状态不能为空", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "企业状态")
        private EnumCompanyStatus status;

        @NotBlank(message = "企业logo访问地址不能为空", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "企业logo访问地址")
        private String logoUrl;

        @NotBlank(message = "营业执照urls不能为空", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "营业执照urls")
        private String businessLicenseImages;

        @NotBlank(message = "父id(如果是本身则为0)不能为空", groups = {VdAdd.class, VdEdit.class})
        @Size(min = 1, max = 255, message = "父id(如果是本身则为0)长度不能超过255", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "父id(如果是本身则为0)")
        private String parentId;

        @NotBlank(message = "根id不能为空", groups = {VdAdd.class, VdEdit.class})
        @Size(min = 1, max = 255, message = "根id长度不能超过255", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "根id")
        private String rootId;

        @NotNull(message = "企业等级不能为空", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "企业等级")
        private EnumCompanyLevel companyLevel;

        @NotNull(message = "是否删除不能为空", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "是否删除")
        private Boolean isDel;

        @ApiModelProperty(value = "英文简称")
        private String companyEnSimpleName;

        @ApiModelProperty(value = "中文简称")
        private String companyCnSimpleName;


    }

    @ApiModel(value = "用户端注册企业")
    @Data
    class UserRegisterNewCompanySaveVo {

        @NotBlank(message = "公司名称不能为空", groups = {VdAdd.class, VdEdit.class})
        @Size(min = 1, max = 255, message = "公司名称长度不能超过255", groups = {UserMapstruct.VdRegisterNewCompany.class})
        @ApiModelProperty(value = "公司名称")
        private String companyName;

        @NotBlank(message = "证件类型Id不能为空", groups = {UserMapstruct.VdRegisterNewCompany.class})
        @ApiModelProperty(value = "公司证件类型Id")
        private String companyCardTypeId;

        @NotBlank(message = "证件类型不能为空", groups = {UserMapstruct.VdRegisterNewCompany.class})
        @ApiModelProperty(value = "公司证件类型")
        private String companyCardTypeName;

        @NotBlank(message = "证件号码不能为空", groups = {UserMapstruct.VdRegisterNewCompany.class})
        @ApiModelProperty(value = "公司证件号")
        private String companyCardNumber;

        @NotBlank(message = "公司地址不能为空", groups = {UserMapstruct.VdRegisterNewCompany.class})
        @ApiModelProperty(value = "公司地址")
        private String companyAddress;

        @NotNull(message = "证件照片不能为空", groups = {UserMapstruct.VdRegisterNewCompany.class})
        @ApiModelProperty(value = "证件照片")
        private AppFileMapstruct.FileVo companyCardFile;

        @ApiModelProperty(value = "业务范围")
        private String businessRange;

        @ApiModelProperty(value = "上级组织")
        private String parentCompanyId;

        @ApiModelProperty(value = "上级组织名称")
        private String parentCompanyName;

        @ApiModelProperty(value = "企业服务能力")
        private List<CompanyServiceTypeMapstruct.SaveVo> companyServiceTypeList;

        @ApiModelProperty(value = "服务地区")
        private List<CompanyServiceAreaMapstruct.SaveVo> companyServiceAreaList;

        @ApiModelProperty(value = "企业资质")
        private List<CompanyAptitudeMapstruct.SaveVo> companyAptitudeList;

        @ApiModelProperty(value = "企业分成规则")
        private BigDecimal companyDivideIntoRuleValue;

        @ApiModelProperty(value = "企业分成规则说明")
        private AppFileMapstruct.FileVo companyDivideIntoRuleFile;

    }

    @ApiModel(value = "设置部门负责人")
    @Data
    class SetCompanyPrincipal {

        @NotBlank(message = "数据ID不能为空")
        @ApiModelProperty(value = "数据ID")
        private String companyDepartmentId;

        @NotBlank(message = "用户不能为空")
        @ApiModelProperty(value = "用户不能为空")
        private String userId;

        @ApiModelProperty(value = "是否负责人")
        private Boolean isPrincipal = false;

    }

    @ApiModel(value = "移除用户")
    @Data
    class RemoveUserVo {

        @NotBlank(message = "公司ID不能为空")
        private String companyId;

        @NotBlank(message = "用户ID不能为空")
        private String userId;

    }

    //-------------------------------- springboot验证标识 --------------------------------

}
